package 寒假作业.LeetCode;

import java.util.HashSet;
import java.util.Set;



public class Num0201 {

    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }

    public ListNode removeDuplicateNodes(ListNode head) {
        if (head == null){
            return head;
        }
        Set<Integer> set = new HashSet<Integer>();
        set.add(head.val);
        ListNode node = head;
        while (node.next != null){
            ListNode cur = node.next;
            if (set.add(cur.val)){
                node = node.next;
            }else {
                node.next = node.next.next;
            }
        }
        return head;
    }
}
